/*******************************************************************************
 * Copyright (c) 2008, 2009 Fabio Mauro - Alberto Terraneo.
 * Permission is granted to copy, distribute and/or modify this document
 * under the terms of the GNU Free Documentation License, Version 1.2
 * or any later version published by the Free Software Foundation.
 *     
 * This program is distributed in the hope that it will be useful, 
 * but WITHOUT ANY WARRANTY; without even the implied 
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
 * See the GNU Free Documentation License for more details.
 *     
 * You should have received a copy of the GNU Free Documentation 
 * License along with this distribution; if not, send a email to authors:
 * aterraneo <at> users.sourceforge.net
 * bigmoby09 <at> users.sourceforge.net
 *******************************************************************************/
package it.blueocean.acanto.model;

import it.blueocean.acanto.model.common.ABaseEntity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Type;

@Entity
@Table(name = "TB_MENU_ITEMS")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class MenuItem extends ABaseEntity implements Comparable<Object>
{
	private static final long serialVersionUID = 3857045235873928021L;
	
	@Id
	@Column(name = "MENU_ITEM_ID", nullable = false, unique = true)
	private String id;

	@Column(name = "PARENT", nullable = true)
	private String parent;

	@Column(name = "POSITION", nullable = true)
	private int position;

	@Column(name = "MENU_ITEM_TITLE", nullable = true, unique = true)
	private String title;

	@Column(name = "ENABLED", length = 1)
	@Type(type = "org.hibernate.type.TrueFalseType")
	private boolean enabled;
	
	public MenuItem()
    {
    }
	
	public Object clone()
    {
        MenuItem clone = new MenuItem();
        
        clone.setId(getId());            
        clone.setParent(getParent());        
        clone.setPosition(getPosition());
        clone.setTitle(getTitle());
        clone.setEnabled(isEnabled());  
        
        return clone;
    }
    
    public boolean equals(Object anObject)
    {
        return id.equals(anObject);
    }
    
    public String toString()
    {
    	final String TAB = "    ";

		StringBuilder retValue = new StringBuilder();

		return retValue.append("NavigationItem ( ").append(super.toString()).append(TAB)
			.append("id = ").append(this.getId()).append(TAB)
			.append("parent = ").append(this.getParent()).append(TAB)
			.append("position = ").append(this.getPosition()).append(TAB)
			.append("title = ").append(this.getTitle()).append(TAB)
			.append("enabled = ").append(this.isEnabled()).append(TAB)
			.append(" )")
			.toString();
    }
    
    public int compareTo(Object arg0)
    {
        int result = this.getPosition() - ((MenuItem)arg0).getPosition();
        
        if(result < 0)
            return -1;
        else if(result == 0)
            return 0;
        else
            return 1;
    }

    
    /*
     * getter / setter methods
     */
	public String getId()
	{
		return id;
	}

	public void setId(String id)
	{
		this.id = id;
	}

	public String getParent()
	{
		return parent;
	}

	public void setParent(String parent)
	{
		this.parent = parent;
	}

	public int getPosition()
	{
		return position;
	}

	public void setPosition(int position)
	{
		this.position = position;
	}

	public String getTitle()
	{
		return title;
	}

	public void setTitle(String title)
	{
		this.title = title;
	}

	public boolean isEnabled()
	{
		return enabled;
	}

	public void setEnabled(boolean enabled)
	{
		this.enabled = enabled;
	}

}
